package cn.walls1717.wallsmall.cart.vo;

import java.math.BigDecimal;
import java.util.List;

/**
 * 购物车
 *
 * @author walls1717
 * @since 2022/11/14 19:02
 **/
public class CartVO {
    /** 购物项 */
    private List<CartItemVO> items;
    /** 商品总数 */
    private Integer countNum;
    /** 商品类型数量 */
    private Integer countType;
    /** 商品总价 */
    private BigDecimal totalAmount;
    /** 减免价格 */
    private BigDecimal reduce = new BigDecimal("0");

    public List<CartItemVO> getItems() {
        return items;
    }

    public void setItems(List<CartItemVO> items) {
        this.items = items;
    }

    /**
     * 获取商品总数
     *
     * @return 所有类型的商品总数
     */
    public Integer getCountNum() {
        int count = 0;
        if (items == null || items.size() == 0) {
            return count;
        }
        for (CartItemVO item : items) {
            count += item.getCount();
        }
        return count;
    }

    /**
     * 获取商品类型数量
     *
     * @return 商品类型总数
     */
    public Integer getCountType() {
        int count = 0;
        if (items == null || items.size() == 0) {
            return count;
        }
        for (CartItemVO item : items) {
            count += 1;
        }
        return count;
    }

    /**
     * 获取商品总价
     *
     * @return 所有类型商品的总价格
     */
    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal("0");
        if (items == null || items.size() == 0) {
            return amount;
        }
        for (CartItemVO item : items) {
            if (item.getCheck()) {
                BigDecimal totalPrice = item.getTotalPrice();
                amount = amount.add(totalPrice);
            }
        }
        return amount.subtract(getReduce());
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
